<!DOCTYPE html>
<html>
<head lang="zh-CN">
    <meta charset="UTF-8">
    <meta name="viewport" content=" initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <title>我的店铺</title>
    <link href="{$Think.config.RESOURCEURL}wx_assets/css/common.css{$Think.config.RESOURCE_VER}" rel="stylesheet" type="text/css">
    <link rel="stylesheet" type="text/css" href="{$Think.config.RESOURCEURL}wx_assets/quan/shopStart.css{$Think.config.RESOURCE_VER}" />
    <script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/js/zepto.1.1.3.min.js{$Think.config.RESOURCE_VER}"></script>
    <script src="{$Think.config.RESOURCEURL}wx_assets/js/util.js{$Think.config.RESOURCE_VER}" type="text/javascript"></script>
    <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/js/wx_share.js{$Think.config.RESOURCE_VER}"></script>
<style type="text/css">
    .data-end{
        color: #fff
    }
</style>
</head>
<body>
<div class="container">
    <div class="product" id="proBox"></div>
    <a class="ico" onclick="shop.goIndex()"><img src="{$headImgUrl}"/></a>
</div>
<div style="display:none" id="tmp"></div>
</body>
<script type="text/html" id="shopTpl">
    <%if(proList){%>
        <div class="list">
            <%
                var len =proList.length;
                for(var i=0;i<len;i++){
                    var item=proList[i];
            %>
                <%if(i%2==0) {%>
                    <div class="productList" align="center"  onclick="shop.toDetail('<%=item.detailUrl%>')">
                        <div class="imgbox">
                            <img src="<%=item.shareImg%>"/>
                        </div>
                        <div class="name"><%=item.title%></div>
                        <div class="price"><%=item.description%></div>
                        <div class="price left"><%=item.date%></div>
                    </div>
               <%}%>
           <%}%>
        </div>
        <div class="list">
            <%
                var len =proList.length;
                for(var i=0;i<len;i++){
                    var item=proList[i];
            %>
                <%if(i&& i%2==1) {%>
                    <div class="productList" style="margin-left:0" align="center"  onclick="shop.toDetail('<%=item.detailUrl%>')">
                        <div class="imgbox">
                            <img src="<%=item.shareImg%>" title="<%=item.name%>"/>
                        </div>
                        <div class="name"><%=item.title%></div>
                        <div class="price"><%=item.description%></div>
                        <div class="price left"><%=item.date%></div>
                    </div>
               <%}%>
           <%}%>
        </div>
    <%}%>
</script>
<script type="text/javascript">
    var baseUrl = '{$Think.config.SERVER_HOST}';
    var shop={
        pageSize:20,
        page:0,
        guid:"{$guid}",
        init:function(){
            var me=this;
            $.util.pageLoading.show();
            me._loadList(me.page,function(){
                $.util.pageLoading.hide();
            });
            this._initEvent();
        },
        goIndex:function(){
            var me=this;
            var p=$.util.getParamAsObject();
            var params={
                "fromGuid":me.guid,
                "miUId":"{$fromUId}",
                "qId":"{$qId}",
                "fromUId":p.fromUId
            };
            params=encodeURIComponent(JSON.stringify(params));
            location.href='{$Think.config.SERVER_HOST}call.html?customerId={$customerId}&module=quan&method=shopIndex&params='+params;
        },
        toDetail:function(detailUrl){
            location.href= detailUrl;
        },
        _initEvent:function(){
            var me=this;
            $.util.initDataLoading({
                me:shop,
                lastChildren:function(){
                    return $("#proBox .list:last");
                },
                page:function(){
                    return shop.page;
                },
                pageCount:function(){
                    return shop.pageCount;
                }
            });
        },
        _renderList:function(data,page,callback){
            var me=this;
            if(data){
                var html=template("shopTpl", data),
                        container=$("#proBox");
                $("#tmp").html(html);
                var list=container.find(".list");
                var tmpList=$("#tmp").find(".list");
                if(list.size()<1) {
                    container.html(html);
                } else {
                    list.eq(0).append(tmpList.eq(0).html());
                    list.eq(1).append(tmpList.eq(1).html());
                    $("#tmp").html("");
                }
                me.page=page;
                me.pageCount=data.pageCount;
                callback && callback();
            }
        },
        _loadList:function(page,callback){
            var me=this;
            $.req.get("call.json?module=quan&customerId={$customerId}&method=getShopStartList",{
                userName:"{$userName}",
                params:{
                    "qId":"{$qId}",
                    "start":page,
                    "limit":me.pageSize,
                    "fromUId":"{$fromUId}"
                }
            },function(data){
                if(data){
                    me._renderList(data,page,callback);
                }
            });
        },
        share:function(){
            var fromGuid=$.util.getParamByObject("fromGuid") || "";
            $.req.get("call.json?customerId={$customerId}&module=quan&method=saveShare&userName={$userName}",{
                params:{
                    "qId":"{$qId}",
                    "sId":"{$sId}",
                    "guid":"{$guid}",
                    "fromGuid":fromGuid,
                    "miUId":"{$fromUId}",
                    "shareType":1,
                    "fromPage":"shopStart"
                }
            },function(data){
                if(data && !data.code){

                }
            });
        },
        getShareUrl:function(){
            var qId=$.util.getParamByObject("qId");
            var shareUrl="";
            var me=this;
            var params={
                "fromGuid":me.guid,
                "miUId":"{$fromUId}",
                "qId":"{$qId}",
                "fromUId":"{$fromUId}"
            };
            params=encodeURIComponent(JSON.stringify(params));
            shareUrl=baseUrl+'call.html?customerId={$customerId}&module=quan&scope=1&method=shopStart&params='+params;
            return shareUrl;
        }
    }
    shop.init();
    var shareUrl=shop.getShareUrl();
    wx_share.init({
            "title":"{$nickName}的密友圈",
            "desc":'{$slogan}',
            "link":shareUrl,
            "imgUrl":"{$headImgUrl}",
            "pkg":{
                "appId": '{$pkg.appId}',
                "timestamp": {$pkg.timestamp},
                "nonceStr": '{$pkg.nonceStr}',
                "signature": '{$pkg.signature}'
            },
            success:function(config,shareType){
            var qId=$.util.getParamByObject("qId");
            var fromGuid=$.util.getParamByObject("fromGuid") || "";
            $.req.get("call.json?customerId={$customerId}&module=quan&method=saveShare&userName={$userName}",{
                params:{
                    "qId":qId,
                    "sId":"{$sId}",
                    "guid":shop.guid,
                    "fromGuid":fromGuid,
                    "miUId":"{$fromUId}",
                    "shareType":shareType,
                    "fromPage":"shopIndex"
                }
            },function(data){
                if(data && !data.code){
                    shop.guid=data.guid;
                }
            });
        }
    });
</script>
</html>